/**
 * GTPInterface allows interaction through the Go Text Protocol
 */
class GoInterface {

  private int protocol_version = 0; // GTP protocol version supported
  // GTP commands
  private final static String BOARDSIZE = "boardsize"; // Setup Command
  private final static String CLEAR_BOARD = "clear_board"; // Setup Command
  private final static String FINAL_SCORE = "final_score"; // Tournament Command
  private final static String FINAL_STATUS_LIST = "final_status_list"; // Tournament Command
  private final static String FIXED_HANDICAP = "fixed_handicap"; // Setup Command
  private final static String GENMOVE = "genmove"; // Core Play Command
  private final static String KNOWN_COMMAND = "known_command"; // Admin Command
  private final static String KOMI = "komi"; // Setup Command
  private final static String LIST_COMMANDS = "list_commands"; // Admin Command
  private final static String LOADSGF = "loadsgf"; // Regression Command
  private final static String NAME = "name"; // Admin Command
  private final static String PLACE_FREE_HANDICAP = "place_free_handicap"; // Setup Command
  private final static String PLAY = "play"; // Core Play Command
  private final static String PROTOCOL_VERSION = "protocol_version"; // Admin Command
  private final static String QUIT = "quit"; // Admin Command
  private final static String REG_GENMOVE = "reg_genmove"; // Regression Command
  private final static String SET_FREE_HANDICAP = "set_free_handicap"; // Setup Command
  private final static String SHOWBOARD = "showboard"; // Debug Command
  private final static String TIME_LEFT = "time_left"; // Tournament Command
  private final static String TIME_SETTINGS = "time_settings"; // Tournament Command
  private final static String UNDO = "undo"; // Core Play Command
  private final static String VERSION = "version"; // Admin Command
  // array of supported commands
  private String[] list_commands = {
    LIST_COMMANDS,
    PROTOCOL_VERSION
  };
  
  public static void main(String[] args) {
    GoInterface testInterface = new GoInterface();
    if(args.length>0) {
      System.out.println("Command line parameters detected!"); // User is trying to do something
      if(args[0].equals("list_commands")) {
        System.out.println("User has requested that known commands be listed!");
        testInterface.listCommands("42"); // test command ID = 42
      }
    }
    System.out.println("Done.");
  }

  public String nextCommand() {
    // read next line from input
    // parse line: [id] command [argument] #comment
    /*
      Remove all occurences of CR and other control characters except for HT and LF.
      For each line with a hash sign (#), remove all text following and including this character.
      Convert all occurences of HT to SPACE.
      Discard any empty or white-space only lines.
    */
    String ID = new String();
    // check to see if the command is for me
      return null; // interface handled command, so nothing for chassis to do
    // if not, pass the command back for processing
    // return new String("***INSERT COMMAND HERE***");
  }
  
  private void listCommands(String ID) {
    String line = new String("="+ID+" ");
    for(int i=0;i<list_commands.length;i++){
      System.out.println(line+list_commands[i]); // maybe should return and output string in main func
      line = null;
    }
    System.out.println();
  }
  // must support these commands for kgs
  // http://www.weddslist.com/kgs/how/kgsGtp.html
  /*
    boardsize
    play
    genmove
  */
  
  
  // should support these commands
  /*
    list_commands
    clear_board
    place_free_handicap
    set_free_handicap
  */
  
  // other commands
  /*
    name
    version
    quit
    komi
    undo
    TOURNAMENT COMMANDS
    time_settings
    kgs-time_settings
    time_left
    final_status_list - required for rated games
    kgs-genmove_cleanup
  */
  
  
  
}
